***************************************************************************************
*** Replication code for "State Repression and Opposition Survival in Pinochet's Chile"
*** by Consuelo Amat 
*** CPS, January 2023
*********************

*** PAPER ***

** Software and version: STATA 17.0

** Load Data
clear all
cd "~/directory" // fill in
insheet using "sequence_captures.csv"

**Install programs
ssc install rangestat


** Figure 7:

*Adding survival model structure to data:
gen date_mdy = mdy(month_detention, day_detention, year_detention)
gen date_mdy2 = mdy(month_detention, day_detention, year_detention)
format date_mdy2 %td
stset date_mdy 

*Calculate average number of captures in a 30-day period:
gen obs = .
replace obs = 1 if orgid!=.
summ obs

sort year_detention month_detention day_detention

rangestat (sum) sum_speed_detention=obs, interval(date_mdy 0 30) by(orgid) 
gen speed_detention=.
replace speed_detention= sum_speed_detention/30

*Create variables to compare MIR to PS, and MIR to PC:
gen mir_vs_ps = .
replace mir_vs_ps=1 if orgid==101
replace mir_vs_ps=0 if orgid==132

gen mir_vs_pc = .
replace mir_vs_pc=1 if orgid==101
replace mir_vs_pc=0 if orgid==131


**OLS models for plot:
*Comparing MIR vs. PS and PC: Sept 11, 1973-1976, inclusive
regress speed_detention mir region_n if (date_mdy>5001 & date_mdy<6199)  
estimates store Sept1173_Dec76MIR
*Comparing MIR vs. PS and PC: whole period 
regress speed_detention mir region_n 
estimates store wholeperiodMIR
*Comparing MIR vs. PS: Sept 11, 1973-1976, inclusive 
regress speed_detention mir_vs_ps region_n if (date_mdy>5001 & date_mdy<6199) 
estimates store Sept1173_Dec76MIRPS
*Comparing MIR vs. PS: whole period 
regress speed_detention mir_vs_ps region_n 
estimates store wholeperiodMIRPS
*Comparing MIR vs. PC: Sept 11, 1973-1976, inclusive 
regress speed_detention mir_vs_pc region_n if (date_mdy>5001 & date_mdy<6199) 
estimates store Sept1173_Dec76MIRPC
*Comparing MIR vs. PC: whole period 
regress speed_detention mir_vs_pc region_n 
estimates store wholeperiodMIRPC

*Plot main coefficients from all models:
coefplot Sept1173_Dec76MIR wholeperiodMIR Sept1173_Dec76MIRPS wholeperiodMIRPS Sept1173_Dec76MIRPC wholeperiodMIRPC, horizontal xline(0) drop(_cons) 

